@extends('layout.page')
@section('title','行为管理 - 创建')
@section('static-page')
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>行为管理 <small>添加</small></h5>
            </div>
            <div class="ibox-content">
                <form method="post" action="/ceb/behavior/doCreate" class="form-horizontal">
                    {{csrf_field()}}
                    <div class="form-group ">
                        <label class="col-sm-2 control-label">行为名称：</label>
                        <div class="col-sm-6">
                            <div class="row">
                                <div class="col-md-8">
                                    <input type="text" name="info[name]"
                                           placeholder="行为名称" class="form-control">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>
                    <div class="form-group ">
                        <label class="col-sm-2 control-label">备注：</label>
                        <div class="col-sm-10">
                            <div class="row">
                                <div class="col-md-6">
                                    <input type="text" name="info[remark]"
                                           placeholder="备注" class="form-control">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group ">
                        <label class="col-sm-2 control-label">行为值：</label>
                        <div class="col-sm-3">
                            <div class="row">
                                <div class="col-md-8">
                                    <input type="text" name="info[value]"
                                           placeholder="行为值" class="form-control">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group ">
                        <label class="col-sm-2 control-label">行为分类值：</label>
                        <div class="col-sm-3">
                            <div class="row">
                                <div class="col-md-8">
                                    <input type="text" name="info[type_value]"
                                           placeholder="行为分类值" class="form-control">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group ">
                        <label class="col-sm-2 control-label">行为分类名称：</label>
                        <div class="col-sm-3">
                            <div class="row">
                                <div class="col-md-8">
                                    <input type="text" name="info[type_name]"
                                           placeholder="行为分类" class="form-control">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>

                    <div class="form-group ">
                        <label class="col-sm-2 control-label">状态：</label>
                        <div class="col-sm-4">
                            <div class="row">
                                <div class="col-md-4 m-b-xs">
                                    <select  name="info[status]" class="form-control input-s-sm inline">
                                        @foreach($status as $key => $val)
                                            <option  value="{{ $val['id'] }}">{{ $val['name']}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-2">
                            <button class="btn btn-primary" type="button" id="btn-save">保存内容</button>
                            <a href="javascript:void(0);" onclick="window.history.back()">
                                <button class="btn btn-white" type="button">取消</button>
                            </a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
@section('javascript')
    <script>
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
            var ex_int = /^\d+$/;
            $("#btn-save").click(function () {
                var dom_name = $("input[name='info[name]']");
                if(dom_name.val().length==0){
                    dom_name.next().html("名称不能为空");
                    dom_name.parents(".form-group").addClass('has-error');
                    return false;
                }
                dom_name.next().html("");
                dom_name.parents(".form-group").removeClass('has-error');
                var dom_remark = $("input[name='info[remark]']");
                if(dom_remark.val().length==0){
                    dom_remark.next().html("备注不能为空");
                    dom_remark.parents(".form-group").addClass('has-error');
                    return false;
                }
                dom_remark.next().html("");
                dom_remark.parents(".form-group").removeClass('has-error');

                var dom_value = $("input[name='info[value]']");
                if(dom_value.val().length==0){
                    dom_value.next().html("行为值不能为空");
                    dom_value.parents(".form-group").addClass('has-error');
                    return false;
                }
                if(!ex_int.test(dom_value.val())){
                    dom_value.next().html("行为值必须为整数");
                    dom_value.parents(".form-group").addClass('has-error');
                    return false;
                }
                dom_value.next().html("");
                dom_value.parents(".form-group").removeClass('has-error');

                var dom_type_value = $("input[name='info[type_value]']");
                if(dom_type_value.val().length==0){
                    dom_type_value.next().html("行为分类值不能为空");
                    dom_type_value.parents(".form-group").addClass('has-error');
                    return false;
                }
                if(!ex_int.test(dom_type_value .val())){
                    dom_type_value.next().html("行为分类值必须为整数");
                    dom_type_value.parents(".form-group").addClass('has-error');
                    return false;
                }
                dom_type_value.next().html("");
                dom_type_value.parents(".form-group").removeClass('has-error');

                var dom_type_name = $("input[name='info[type_name]']");
                if(dom_type_name.val().length==0){
                    dom_type_name.next().html("行为分类名称不能为空");
                    dom_type_name.parents(".form-group").addClass('has-error');
                    return false;
                }
                dom_type_name.next().html("");
                dom_type_name.parents(".form-group").removeClass('has-error');

                $('form').submit();
            });
        });
    </script>
@endsection

